//index.js
// 用户，商家，菜单，订单，子订单，支付，搜索，评价
// 自动领取红包，自动使用合适的红红包，前端语音搜索，商家历史订单 评论 
var app = getApp()
var util=require('../../utils/util.js');
Page({
  data: {
    pageType: 3,
    // index
    userInfo: {},
    
    // me
    img: '',
    weiuser:{},

    hadshop:false,
    shopinfo:{}
 
  }, 
  onLoad: function () {
    var that = this 
    
    let userInfo = JSON.parse(wx.getStorageSync("userinfo"));
    let weiuser=wx.getStorageSync("weiuser");
    var shopinfo = wx.getStorageSync("shopinfo");
    that.setData({
    //  userInfo: userInfo,
   //   img: userInfo.avatarUrl,
      weiuser:weiuser,
      shopinfo: shopinfo
    }) 
    this.getmyshop();
    wx.setNavigationBarTitle({
      title: weiuser.nick, 
    })
  },
  //事件处理函数


  toMyPackage: function () {
    wx.navigateTo({
      url: '../myPackage/myPackage'
    })
  },
  toMyShops: function () {
    wx.navigateTo({
      url: '../shop/index' + "?weiuserid=" + this.data.weiuser.id
    })
  },
  toOpenShop: function () {
    wx.navigateTo({
      url: '../suggest/shopapply'
    })
  },
  toGiveOpinion: function () { 
    wx.navigateTo({
      url: '../suggest/suggest'
    })
  },
  toHistoryOrder: function () {
    wx.navigateTo({
      url: '../myPackage/myPackage'
    })
  },
  toOpenAuth:function(){
    wx.navigateTo({
      url: '../userauth/userauth',
    })
  },
  toMyAddress:function(){
    wx.navigateTo({
      url: '../address/address',
    })
  },
  getmyshop:function(){
    var that=this;
    var url = util.url.shop_shop_getshop;
    util.fetchGet(
      url,
      function(ret){
        var hadshop=false;
        if (ret.data && ret.data.id){
          hadshop=true;
          wx.setStorageSync("shopid", ret.data.id);
        }
        that.setData({  
          hadshop: hadshop
        }) 
      }
    )
  }
})
